{  Statement: http://acmp.ru/?main=task&id_task=113
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    i, j, n, ans, k, kk, tt, cur, ci, cj, l, r : longint;
    a : array[0..1010, 0..1010] of boolean;
    f : array[0..1010, 0..1010] of longint;
    ch : char;
    ok : boolean;
    
begin
    reset(input,'input.txt');
    rewrite(output,'output.txt');
    fillchar(f, sizeof(f), 0);
    readln(n);
    for i := 1 to n do begin    
        for j := 1 to n do begin
            read(ch);
            a[i][j] := ch = '1';
        end;
        readln;
    end;
    ans := 0;
    for i := 1 to n do
        for j := 1 to n do
            f[i][j] := f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + byte(a[i][j]);
    l := 1;
    r := n + 1;
    while r > l do begin
        k := (l + r) shr 1;
        kk := n - k + 1;
        tt := k * k;
        ok := false;
        for i := 1 to kk do begin
            for j := 1 to kk do begin
                ci := i + k - 1;
                cj := j + k - 1;
                cur := f[ci][cj] - f[i - 1][cj] - f[ci][j - 1] + f[i - 1][j - 1];
                if cur = tt then begin
                    ok := true;
          ans := max(ans, tt);
                    break;
                end;
            end;    
            if ok then break;
        end;
        if ok then l := k + 1 else r := k;                    
    end;
    write(ans);
end.
